package com.shnu.work.repository;

import com.shnu.work.entity.SystemInformationEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Shinomiya Kaguya
 */
@Repository
public interface SystemInformationRepository extends CrudRepository<SystemInformationEntity, Long> {
    /**
     * 查找所有未删除的记录
     *
     * @return List
     */
    @Query(value = "select * from system_information where is_deleted = 0", nativeQuery = true)
    List<SystemInformationEntity> listAllUndeletedSysInfo();

    /**
     * 清除所有的启用字段
     *
     * @return 行数
     */
    @Modifying
    @Query(value = "update system_information set note_of_2 = 0", nativeQuery = true)
    Integer clearAllAvailableStatus();

    /**
     * 根据id设置启用字段
     *
     * @param id id
     * @return 行数
     */
    @Modifying
    @Query(value = "update system_information set note_of_2 = 1 where id = ?1", nativeQuery = true)
    Integer updateAvailableStatusById(Long id);

    /**
     * 根据id删除
     *
     * @param id id
     * @return 行数
     */
    @Modifying
    @Query(value = "update system_information set is_deleted = 1 where id = ?1", nativeQuery = true)
    Integer removeSysInfoById(Long id);
}
